from tkinter import *

root = Tk()
root.geometry('200x200+200+200')
root.title('消息')

# 鼠标单击事件
def mousetest(event):
    #鼠标位置
    x1,y1 = (event.x, event.y)
    x2,y2 = (event.x_root, event.y_root)
    # 事件绑定的组件
    p = event.widget
    print(x1,x2,y1,y2,p)

# 画图动作
def testdrag(event):
    c1.create_oval(event.x, event.y,event.x+1,event.y)

# 获取按键的相应属性
def keyboardtest(event):
    kcode = event.keycode
    kchar = event.char
    ksym = event.keysym
    print(kcode,kchar,ksym)

c1 = Canvas(root,width=100,height=100,bg='yellow')
c1.pack()

# 事件触发
c1.bind('<Button-1>', mousetest)
c1.bind('<B1-Motion>', testdrag)
root.bind('<KeyPress>', keyboardtest)

root.mainloop()